package cn.edu.wynu;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * 通过xml配置文件配置
 */
public class TestDML {
    public static void main(String[] args) {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("dataSource.xml");
        JdbcTemplate jdbcTemplate = (JdbcTemplate)context.getBean("jdbcTemplate");
        List<Employee> employeesStart = jdbcTemplate.query("select * from t_emp",
                new BeanPropertyRowMapper<>(Employee.class));
        System.out.println(employeesStart);

        String insert = "insert into t_emp(emp_name, emp_salary) values('张三','6000')";
        int update = jdbcTemplate.update(insert);

        List<Employee> employeesEnd = jdbcTemplate.query("select * from t_emp",
                new BeanPropertyRowMapper<>(Employee.class));
        System.out.println(employeesEnd);
    }
}
